//
//  DoctorTextView.m
//  QuickCure1
//
//  Created by apple on 2016/10/31.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "DoctorTextView.h"

@interface DoctorTextView ()

//记录button下的线条
@property (nonatomic,weak)UIImageView *Line;

//记录textView
@property (nonatomic,weak)UITextView *textView;

@end


@implementation DoctorTextView

- (instancetype)init{
    
    if (self = [super init]) {
        [self setupUI];
    }
    return self;
}
#pragma mark
#pragma mark - 界面搭建
- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];
#pragma mark - 添加button中间的分隔线
    //添加按钮中间的分隔线
    UIView *midView = [[UIView alloc]init];
    midView.backgroundColor = [UIColor darkGrayColor];
    [self addSubview:midView];
    [midView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(10);
        make.size.mas_equalTo(CGSizeMake(2, 30));
    }];
    
    //整个View的宽度
//    CGFloat width = self.bounds.size.width;
#pragma mark - 添加左侧按钮
    //左侧按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //按钮信息配置
    [leftButton setTitle:@"接诊条件" forState:UIControlStateNormal];
    [leftButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [self addSubview:leftButton];
    //约束
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(5);
        make.leading.equalTo(self).offset(20);
        make.trailing.equalTo(midView.mas_leading).offset(-20);
        make.height.equalTo(@40);
    }];
    //添加监听
    [leftButton addTarget:self action:@selector(clickLeftButton) forControlEvents:UIControlEventTouchUpInside];
    
#pragma mark - 添加左侧按钮下的线条
    //按钮下的线条
    UIImageView *Line = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nav"]];
    [self addSubview:Line];
    [Line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(leftButton);
        make.top.equalTo(leftButton.mas_bottom);
        make.height.equalTo(@3);
    }];
    //属性赋值
    self.Line = Line;
    
    
#pragma mark - 添加右侧按钮
    //右侧按钮
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //按钮信息配置
    [rightButton setTitle:@"医生简介" forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [self addSubview:rightButton];
    //约束
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(5);
        make.leading.equalTo(midView.mas_trailing).offset(20);
        make.trailing.equalTo(self).offset(-20);
        make.height.equalTo(@40);
    }];
    //添加监听
    [rightButton addTarget:self action:@selector(clickRightButton) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark
#pragma mark - 左侧按钮的监听方法
- (void)clickLeftButton{
    //发送通知
    self.isLeftButton = YES;
    [self sendActionsForControlEvents:UIControlEventValueChanged];
    
    [UIView animateWithDuration:0.5 animations:^{
        self.Line.transform = CGAffineTransformIdentity;
    }];
}

#pragma mark
#pragma mark - 右侧按钮的监听方法
- (void)clickRightButton{
    //发送通知
    self.isLeftButton = NO;
    [self sendActionsForControlEvents:UIControlEventValueChanged];
    
    CGFloat width = self.bounds.size.width;
    [UIView animateWithDuration:0.5 animations:^{
        self.Line.transform = CGAffineTransformMakeTranslation(width/2, 0);
    }];
}



- (void)setOffsetX:(CGFloat)offsetX{
    
    _offsetX = offsetX;
    self.Line.transform = CGAffineTransformMakeTranslation(offsetX/2, 0);
}


@end





















